var temp
$(document).ready(function() {
	
	$("#closeList").click(function() {
		$("#listopen").hide();
		$("#closeList").hide();
		$("#place").hide();
		$("#openlist").show();
		$("#map-canvas-myplace .gmnoprint:last").prev().css('margin-left', '20px');
		$("#mylist").hide();
	});
	$("#openlist").click(function() {
		$("#listopen").show();
		$("#place").show();
		$("#openlist").hide();
		$("#closeList").show();
		$("#map-canvas-myplace .gmnoprint:last").prev().css('margin-left', '490px');
		$("#mylist").show();
	});
	// =========================
	$("#CommentInFavou").keydown(
			function(event) {
				if (event.keyCode == 13) {
					
					var contentCM = $("#CommentInFavou").val()
				//	alert(contentCM)
					$.ajax({
						url : "saveCommentsub",
						type : 'GET',
						data : {
							cm : contentCM,
							placeID : temp,
						},
						dataType : 'JSON',
						success : function(response) {
							var result = response;
							var divComment = $("#listAllCommentsub")
							var divTemp = "<div> " + result.userName + ":&nbsp;" +  result.contentofUSER + "</div>"			
							$(divComment).append(divTemp);					
							$("#CommentInFavou").val("");
							
							return false;
						},
						error : function(data) {
						//	alert("Error HEREREERE 2");
						
							return false;
						}
					});
					 event.preventDefault();
				
				}
				
			});
});

function clickOnPlaceItem(e) {
	$("#listAllCommentsub").html('');
	$("#listAllOldComment").html('');
//	$("#div-black").show();
	$(".superContainer").show();
	temp = e.id;
	var htmldata = '';
	// test1
	 $.ajax({
		  url : "placeDetail",
		  type : "GET",
		  data : "placeID="+temp,
		  success:function(response){
		       
		   //alert("succeess");
		   var result = response;
		
		   $("#addressValue").html(result.propertytype+"<br> Address: "+result.address+"<br> Description: "+result.description+"<br>Bed: "+result.bed+"<br> Bath: "+result.bath+"<br>Price: "+result.price);
		   $("#contactplace").html(result.nameContact+"<br> Phone: "+result.phoneContact+"<br> Email: "+result.emailContact);
		   $("#imageplace").html('<img src="/Lemon/Avatar/getAvatar?placeID=' + temp +  '" width=470px height=260px />')
		   //
		  }
		
		 });
	// test1
	$.ajax({
		url : "listAllComment",
		type : 'GET',
		data : {
			placeid : temp
		},
		contentType : "application/json; charset=utf-8",
		success : function(data) {
			var newest = $("#listAllOldComment");
			for ( var i = 0; i < data.length; i++) {
				htmldata += data[i].userprofile.fullName + " test "
						+ data[i].content + ';';				
				var divTempCM = "<div> " + data[i].userprofile.fullName + ":&nbsp;"+ data[i].content + " <br> </div>"
				$(newest).append(divTempCM);
			}
		//	alert(htmldata);
		},
		error : function(data) {
		}
	});
	// test count of like
	$.ajax({
		url : "allLike",
		type : 'GET',
		data : {
			placeid : temp
		},
		contentType : "application/json; charset=utf-8",
		dataType : 'JSON',
		success : function(response) {
			var result = response;
			var tempLike = result.totalOfLike;
			$("#countOflike").html(tempLike);
		},

		error : function(data) {
		}

	});
	$.ajax({
		url : "liked",
		type : 'GET',
		data : {
			placeid : temp
		},
		contentType : "application/json; charset=utf-8",
		dataType : 'JSON',
		success : function(data) {
			if (data.result == "yes") {
				$("#dislike").show();
				$("#like").hide();
			} else {
				$("#like").show();
				$("#dislike").hide();
			}
		},

		error : function(data) {
		}

	});

}

function isLike1sub(e) {
	var txt = e.id;
	if (txt == "like") {
		$("#like").hide();
		$("#dislike").show();
		$.ajax({
			url : "isLikeUsersub",
			type : 'GET',
			data : {
				placeid : temp,
				testLike : true,
			},
			contentType : "application/json; charset=utf-8",
			dataType : 'JSON',
			success : function(response) {
				var result = response;
				var tempLike = result.totalLike;
				$("#countOflike").html(tempLike);
			},
			error : function(data) {
			}
		});

	}
	if (txt == "dislike") {
		$("#dislike").hide();
		$("#like").show();

		$.ajax({
			url : "isDisLikeUsersub",
			type : 'GET',
			data : {
				placeid : temp,
				testLike : true,
			},
			contentType : "application/json; charset=utf-8",
			dataType : 'JSON',
			success : function(response) {
				var result = response;
				var tempLike = result.disLike;
				$("#countOflike").html(tempLike);
			},
			error : function(data) {
			}
		});
	}
}



function test(){
	$(".superContainer").hide()
}
function listimage()
{   
	
	var htmlData='';
	var data = [];
	var image = new Object;
//	 $(".superContainer").show();
	$.ajax({
		 url : "listImage",
		 type : "GET",
		 data : "placeID="+temp,
		success:function(response){      
		  //alert("succeess");
		  if(response.length > 0) {
			  for ( var i = 0; i < response.length; i++) {
					image.image='showImage?placeID=' + temp + '&index=' + i;
					data.push(image);
					image = new Object;
				}

			  $('#galleria').galleria({ 
 
				  transition: 'fade' 
				  });
		          Galleria.run('#galleria', {dataSource: data,
		        	  autoplay: 2000,
		        	  wait:true,
		        	  debug:true,	        	
		        	  });	
		         
		  }
		 
		   
	 }
});
}